package com.filldream.fastboot.common.entity.db;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.filldream.fastboot.common.okutil.cls.dto.ClsNewsSimpleItem;
import com.filldream.fastboot.common.util.JsonUtil;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
 * 东财新闻
 */
@Data
@Accessors(chain = true)
public class CfNews {

    @TableId(value = "code", type = IdType.NONE)
    private String code;

    private String title;

    private String image;

    private String mediaName;

    private String uniqueUrl;

    private Date showTime;

    private String sendOwner;

    public List<String> getSendOwnerList() {
        if(StringUtils.isBlank(sendOwner)){
            return new LinkedList<>();
        }
        return JsonUtil.fromJosnArray(  sendOwner, String.class);
    }

    public ClsNewsSimpleItem toClsNewsSimpleItem(){
        ClsNewsSimpleItem item = new ClsNewsSimpleItem();
        item.setTitle( title );
        item.setIsTop(false);
        item.setLinkUrl(uniqueUrl);
        item.setId( code );
        item.setImg( image );
        item.setPublishTime( showTime );
        item.setMediaName( mediaName );
        item.setSourceType(2);
        return item;
    }

}
